package com.qfedu.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qfedu.provider.entity.DbFollow;
import com.qfedu.provider.mapper.DbFollowMapper;
import com.qfedu.provider.mapper.DbFunsMapper;
import com.qfedu.provider.mapper.DbUserDetailMapper;
import com.qfedu.provider.service.DbFollowService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【db_follow(关注)】的数据库操作Service实现
* @createDate 2024-11-23 11:16:39
*/
@Service
@RequiredArgsConstructor// 自动注入
public class DbFollowServiceImpl extends ServiceImpl<DbFollowMapper, DbFollow> implements DbFollowService{
    public final DbUserDetailMapper dbUserDetailMapper;
    public final DbFunsMapper dbFunsMapper;


/*
    @Override
    public R add(FollowUser followUser) {
        //判断被关注用户是否存在
        DbUserDetail dbUserDetail = dbUserDetailMapper.selectOne(new LambdaQueryWrapper<DbUserDetail>().eq(DbUserDetail::getUserId, followUser.getFollowedId()));
        if (dbUserDetail == null){
            return R.error("被关注用户不存在");
        }
        //检查用户状态
        if (dbUserDetail.getDeleted()!=1){
            return R.error("被关注用户已注销");
        }
        //检测是否已经关注
        LambdaQueryWrapper<DbFollow> queryWrapper = new LambdaQueryWrapper<DbFollow>()
                .eq(DbFollow::getUserId, followUser.getUid())
                .eq(DbFollow::getFollowedId, followUser.getFollowedId());
        DbFollow dbFollow = baseMapper.selectOne(queryWrapper);
        if (dbFollow != null) {
            return R.error("已关注该用户");
        }
        //可以关注用户
        dbFollow=new DbFollow(followUser.getUid(), followUser.getFollowedId());
        dbFollow.setCreateTime(new Date());
        if (baseMapper.insert(dbFollow)<=0){
            return R.error("关注失败");
        }
        *//**
         * 用mq  消息队列
         *//*
        //关注一个用户之后需要更新被关注用户的粉丝数
        dbFunsMapper.insert(new DbFuns(followUser.getFollowedId(), followUser.getUid(),));
        //需要更新被关注用户的个人信息中的粉丝数
        DbUserDetail dbUserDetail1 = dbUserDetailMapper.selectById(followUser.getFollowedId());
        dbUserDetail1.setFanNumber(dbUserDetail1.getFanNumber()+1);
        //记录日志

        return R.ok("关注成功");
    }*/
    /**
     * 删除关注
     * test
     */
}




